package com.wlcorp.forcazamis.dao.baseinfo.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ibatis.dao.client.DaoException;
import com.wlcorp.forcazamis.dao.baseinfo.IFactoryDAO;
import com.wlcorp.forcazamis.domain.baseinfo.Factory;

public class FactoryDAOImpl extends HibernateDaoSupport implements
		IFactoryDAO {

	@SuppressWarnings("unchecked")
	public List getFactoryList(Factory factory) throws DaoException {
		StringBuffer sqlString = new StringBuffer("from Factory as factory where 1=1 and factory.deleteFlag=false");
		if(null != factory && null != factory.getFactoryCode()){
			sqlString.append(" and factory.factoryCode = '").append(factory.getFactoryCode())
				.append("'");
		}
		return getHibernateTemplate().find(sqlString.toString());
	}

	public Factory getFactoryById(Long factoryId) throws DaoException {
		return (Factory)getHibernateTemplate().get(Factory.class,factoryId);
	}

	public void deleteFactory(Factory factory) throws DaoException {
		factory.setDeleteFlag(true);
		getHibernateTemplate().update(factory);
	}

	public void saveFactory(Factory factory) throws DaoException {
		getHibernateTemplate().saveOrUpdate(factory);
	}

}
